<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/15
 * Time: 15:47
 */

namespace app\admin\model;


use think\Model;

class YearSurvey extends Model
{
    public function initialize()
    {
        $time = time();
        //当月有几天
        $this->year = getdate($time)['year'];
        $this->mon = getdate($time)['mon'];
        $this->day = getdate($time)['mday'];
    }

    public static function getTotal()
    {
        $total['order_total_money'] = self::sum('order_total_money');             //订单总金额
        $total['user_total'] = self::sum('user_total');                           //用户数
        $total['order_total'] = self::sum('order_total');                         //订单数
        $total['order_profit_money'] = self::sum('order_profit_money');           //利润总金额
        return $total;
    }

    public function getToDay()
    {
        return self::where(['year' => $this->year,'mon' => $this->mon,'day' => $this->day])->field('order_total_money,user_total,order_total,order_profit_money')->find();
    }

    public function getYesterDay()
    {
       return YearSurvey::where(['year' => $this->year,'mon' => $this->mon,'day' => $this->day - 1])->field('order_total_money,user_total,order_total,order_profit_money')->find();

    }

    public function getToWeek()
    {
        $week['order_total_money'] = self::where(['year' => $this->year,'mon' => $this->mon])->where('day','>=',$this->day - 7)->where('day','<',$this->day)->sum('order_total_money');

        $week['user_total'] = self::where(['year' => $this->year,'mon' => $this->mon])->where('day','>=',$this->day - 7)->where('day','<',$this->day)->sum('user_total');

        $week['order_total'] = self::where(['year' => $this->year,'mon' => $this->mon])->where('day','>=',$this->day - 7)->where('day','<',$this->day)->sum('order_total');

        $week['order_profit_money'] = self::where(['year' => $this->year,'mon' => $this->mon])->where('day','>=',$this->day - 7)->where('day','<',$this->day)->sum('order_profit_money');

        return $week;
    }

    public function getToMon()
    {
        $toMon['order_total_money'] = self::where(['year' => $this->year,'mon' => $this->mon])->sum('order_total_money');
        $toMon['user_total'] = self::where(['year' => $this->year,'mon' => $this->mon])->sum('user_total');
        $toMon['order_total'] = self::where(['year' => $this->year,'mon' => $this->mon])->sum('order_total');
        $toMon['order_profit_money'] = self::where(['year' => $this->year,'mon' => $this->mon])->sum('order_profit_money');
        return $toMon;
    }
}